﻿using HotChocolate.Stitching.Merge;

namespace GlobalGatewayDemo.DirectiveMergeHandlers;

public class IgnoreDirectiveHandler : IDirectiveMergeHandler
{
    private readonly MergeDirectiveRuleDelegate _next;

    public IgnoreDirectiveHandler(MergeDirectiveRuleDelegate next)
    {
        _next = next;
    }

    public void Merge(
        ISchemaMergeContext context,
        IReadOnlyList<IDirectiveTypeInfo> directives)
    {
        IDirectiveTypeInfo? directive = directives.First();

        if (directive.Definition.Name.Value.Equals("delegate", StringComparison.InvariantCultureIgnoreCase) ||
            directive.Definition.Name.Value.Equals("computed", StringComparison.InvariantCultureIgnoreCase) || 
            directive.Definition.Name.Value.Equals("source", StringComparison.InvariantCultureIgnoreCase))
        {
            return;
        }

        _next(context, directives);
    }
}